﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Text.RegularExpressions;

using KaixinRobot;

namespace KaixinHouse
{

    public class Garden : Component
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public string rank = null;
        public bool hasPlantedMaxSharedFileds = false;

        public Collection<Seed> seedList = null;
        public Collection<Fruit> fruitList = null;

        //用于Account里面初始化Garden
        public Garden(Account acc)
            : base(acc)
        {
        }

        public override bool Action()
        {
            if ((this.config.doGarden == 1))
            {
                if (!logon(this.identity)) return false;
                RunTime.setCurEnv(this.identity.userMail, "garden");
                KXWeb.Garden.Get_Main();

                //取得用户当前的种子，以防止浪费
                this.seedList = Seed.makeList();

                //处理自家花园
                this.handleGardenOwn();

                //照看朋友花园
                this.handleGardenFriend();

                //盗窃朋友花园
                this.stealGardenFriend();

                TraceLog.PrintLn("");
            }
            return true;
        }

        protected bool stealGardenFriend()
        {
            if ((this.config.stealList.Count <= 0) && (this.config.stealOthers != 1))
            {
                //没有指定偷窃列表
                TraceLog.PrintLn("StealList为空！");
                return false;
            }
            if (this.config.stealOthers == 1)
            {
                //动态获得偷窃列表
                //http://www.kaixin001.com/house/garden/getfriendmature.php?verify=525328_1062_525328_1240192144_c46cd343a9ad928650d35e033810d8b2&r=0.8011484784074128
                string content = KXWeb.Garden.Get_FriendMature();
                //{"uid":12900966,"realname":"\u5f20\u96c5\u5982","online":0,"icon20":"http:\/\/pic.kaixin001.com\/logo\/90\/9\/20_12900966_1.jpg","blove":0},
                TextParser tp = new TextParser(content, "{\"uid\":", ",");
                string uid = null;
                while ((uid = tp.getNextStrBtw()) != null)
                {
                    int iuid = TextParser.GetInteger(uid);
                    if (iuid <= 0) continue;
                    if (this.config.stealList.Contains(iuid)) continue;
                    this.config.stealList.Add(iuid);
                }
            }

            TraceLog.PrintLn("开始盗窃朋友的花园 ...... ");
            foreach (int uid in this.config.stealList)
            {
                if (RunTime.needRunAgain()) break;
                TraceLog.PrintLn("盗窃朋友 = {0} ...... ", uid);

                UserIdentity user = new UserIdentity();
                user.userIdx = "" + uid;

                string content = KXWeb.Garden.Get_Config(user.userIdx);
                Collection<Field> fieldList = Field.makeList(content);
                Seed seed = this.config.getProperSeed(TextParser.GetInteger(this.rank));

                int harvested = this.handleFields(fieldList, user, seed);
                TraceLog.PrintLn("");
            }

            return true;
        }

        protected bool handleGardenFriend()
        {
            if (this.config.tcareList.Count <= 0)
            {
                TraceLog.PrintLn("CareList为空！");
                return false;
            }

            //种共享地及照看朋友的花园
            TraceLog.PrintLn("开始照看朋友的花园 ...... ");

            foreach (int uid in this.config.tcareList)
            {
                if (RunTime.needRunAgain()) break;
                TraceLog.PrintLn("照看朋友 = {0} ...... ", uid);

                UserIdentity user = new UserIdentity();
                user.userIdx = "" + uid;
                string content = KXWeb.Garden.Get_Config(user.userIdx);
                Collection<Field> fieldList = Field.makeList(content);
                Seed seed = this.config.getProperSeed(TextParser.GetInteger(this.rank));

                int harvested = this.handleFields(fieldList, user, seed);
                TraceLog.PrintLn("");
            }
            TraceLog.PrintLn("");
            return true;
        }

        protected bool handleGardenOwn()
        {
            UserIdentity user = new UserIdentity();
            user.userIdx = "0";
            string contentAll = KXWeb.Garden.Get_Config(user.userIdx);

            //取得用户当前资金
            //<cashtip>我的现金余额123590</cashtip>
            string cashstr = TextParser.GetHtmlContent(contentAll, "cashtip");
            this.cash = TextParser.ReadFirstInteger(cashstr);

            //取得用户级别以确定使用的种子
            this.rank = TextParser.GetHtmlContent(contentAll, "rank");
            Seed seed = this.config.getProperSeed(TextParser.GetInteger(this.rank));

            //打印调试信息
            TraceLog.PrintLn("UserLevel={0}, Cash={1}, UseSeed={2}/{3}", this.rank, this.cash, seed.seedid, seed.name);

            //Get FieldList
            Collection<Field> fieldList = Field.makeList(contentAll);

            //处理自己的花园
            TraceLog.PrintLn("处理自己的花园 ......");
            int harvested = this.handleFields(fieldList, user, seed);
            TraceLog.PrintLn("");

            //赠送庄稼, 一天只能赠送一次
            if (RunTime.isANewDay()) this.sendFruit();

            //贩卖收割的庄稼
            if (harvested > 0) this.sellFruit();

            return true;
        }

        private int sendFruit()
        {

            TraceLog.PrintLn("开始赠送劳动果实 ......");

            if (TextParser.GetInteger(this.rank) < 6)
            {
                TraceLog.PrintLn("用户不满6级，不进行赠送！");
                return 0;
            }

            if (this.isAPoorMan())
            {
                TraceLog.PrintLn("穷人一只，不进行赠送！");
                return 0;
            }

            if (this.config.sendCrops == 0)
            {
                TraceLog.PrintLn("SendCrops==0，不进行赠送！");
                return 0;
            }

            if (this.config.sendList.Count <= 0)
            {
                TraceLog.PrintLn("赠送列表为空，不进行赠送！");
                return 0;
            }

            this.fruitList = Fruit.makeList(false);
            int ucnt = 0, fcnt = 0;
            while ((ucnt < this.config.sendList.Count) && (fcnt < fruitList.Count))
            {
                TraceLog.Print("赠送果实 [SD={0}]*{1} 给{2} ......", fruitList[fcnt].seedid, fruitList[fcnt].fruitnum, this.config.sendList[ucnt]);

                string content = KXWeb.Garden.Do_SendFruit(""+this.config.sendList[ucnt], ""+fruitList[fcnt].seedid, ""+fruitList[fcnt].fruitnum);

                if (content.IndexOf("succ") >= 0)
                {
                    TraceLog.PrintLn("succ");
                }
                else
                {
                    TraceLog.PrintLn("fail");
                }

                fcnt++;
                ucnt++;
            }

            TraceLog.PrintLn("");
            return 0;
        }

        private int sellFruit()
        {
            TraceLog.PrintLn("开始买出劳动果实 ......");

            if ((this.config.sellCrops == 1) || (this.isAPoorMan()))
            {
                if (this.isAPoorMan()) TraceLog.PrintLn("穷人一只，强制买出所有果实！");

                //GET /house/garden/sellfruit.php?verify=525328%5F1062%5F525328%5F1236134647%5Febff7bfa2d1501e7af474cb17468c99b&all=0&seedid=3&num=1
                TraceLog.Print("Selling all products ...... ");
                string sellContent = KXWeb.Garden.Do_SellFruit();
                if (sellContent.IndexOf("succ") >= 0)
                {
                    //string totalprice = Tool.GetMidString(sellContent, "<totalprice>", "</totalprice>");
                    string totalprice = (new TextParser(sellContent)).getStrBtw("<totalprice>", "</totalprice>");
                    TraceLog.PrintLn("OK! 获利 = " + totalprice + "元");
                }
            }

            TraceLog.PrintLn("");
            return 0;
        }

        private bool GardenAction(KXWeb.Garden.Action act, string fuid, int farmnum, string seedid)
        {
            string actionName = act.ToString();

            TraceLog.Print("{0}.{1}: {2} ......", fuid, farmnum, actionName);

            string content = KXWeb.Garden.Do_Garden(act, fuid, "" + farmnum, seedid);

            string succSign = "succ";
            if (content.IndexOf(succSign) >= 0)
            {
                TraceLog.PrintLn(succSign);
                return true;
            }
            else
            {
                TraceLog.PrintLn("fail");
                return false;
            }
        }

        private bool canHarvest(int uid)
        {
            if (uid <= 0) return true;
            if (this.config.stealList.Contains(uid)) return true;
            if (this.config.stealOthers == 1) return true;

            return false;
        }


        //userID == 0, this user.
        protected int handleFields(Collection<Field> fieldlst, UserIdentity user, Seed seed)
        {
            if ((fieldlst == null) || (fieldlst.Count < 1)) return -1;
            if ((seed == null) || (user == null)) return -1;

            string forUserID = user.userIdx;
            int forUserNbr = TextParser.GetInteger(user.userIdx);

            //抢先进行收割，防止被偷，再做其它操作
            int harvested = 0;
            foreach (Field fld in fieldlst)
            {
                //忽略非法/不可操作土地
                if ((fld.farmnum < 0) || (fld.status == 0)) continue;

                //设置下次运行时间，只有庄稼处于生长阶段，并且指定了照看庄稼，并且庄稼的主人是自己
                if ((fld.cropsstatus == 1) && (this.config.watchCrops == 1) && (forUserNbr == 0))
                {
                    RunTime.exptRunAt(fld.harvestTime);
                }

                //如果可以收获，收割, BTW: 对于好友，这就是盗窃
                if ((fld.cropsstatus == 2) && (this.canHarvest(forUserNbr)))
                {
                    if (GardenAction(KXWeb.Garden.Action.Havest, forUserID, fld.farmnum, "0"))
                    {
                        fld.cropsstatus = 3;
                        harvested++;
                    }
                }
            }

            //做除收割之外的其它操作
            foreach (Garden.Field fld in fieldlst)
            {
                //忽略非法/不可操作/共享地块
                if ((fld.farmnum < 0) || (fld.status == 0)) continue;

                //判断是否需要中止此用户的操作
                if ((this.hasPlantedMaxSharedFileds) && (forUserNbr != 0)) break;

                //如果状态不正常，除害，目前只做记录
                if ((fld.status != 1) || (fld.cropsstatus > 3))
                {
                    TraceLog.PrintLn("{0}.{1}: status={2}, corpsstatus={3}", forUserID, fld.farmnum, fld.status, fld.cropsstatus);
                    TraceLog.PrintLn(fld.farm);
                    TraceLog.PrintLn(fld.crops);
                    //continue;
                }

                //浇水
                if ((fld.water < 5) && (GardenAction(KXWeb.Garden.Action.Water, forUserID, fld.farmnum, "0")))
                {
                    fld.water = 5;
                }

                //除虫
                if ((fld.vermin == 1) && (GardenAction(KXWeb.Garden.Action.Antivermin, forUserID, fld.farmnum, "0")))
                {
                    fld.vermin = 0;
                }

                //除草
                if ((fld.grass == 1) && (GardenAction(KXWeb.Garden.Action.Antigrass, forUserID, fld.farmnum, "0")))
                {
                    fld.grass = 0;
                }

                //判断土地能否进行操作
                bool operational = false;
                //如果是本人的土地，则非共享的是可以操作的
                if ((forUserNbr == 0) && (fld.shared != 1)) operational = true;

                //如果是朋友的土地，则共享的是可以操作的
                //不种共享地，只照顾共享地 2009-3-30
                //if ((forUserNbr != 0) && (fld.shared == 1)) operational = true;

                //如果土地可以操作，则进行锄地/买种子/播种等操作
                if (operational)
                {
                    //如果正常生长，不做任何事情
                    if (fld.cropsstatus == 1) continue;

                    //如果已经收获过，锄地
                    if ((fld.cropsstatus == 3) || (fld.cropsstatus == -1))
                    {
                        if (GardenAction(KXWeb.Garden.Action.Plough, "0", fld.farmnum, "0"))
                        {
                            fld.cropsstatus = -1;
                        }
                    }
                    //没有庄稼，买种子，并播种
                    if (fld.cropsstatus == -1) this.seeding(forUserNbr, fld, seed);
                }
            }
            return harvested;
        }

        private bool hasSeed(Seed seed)
        {
            if (this.seedList == null) return false;
            foreach (Seed sd in this.seedList)
            {
                if ((sd.seednum > 0) && (sd.seedid == seed.seedid))
                {
                    //sd.seednum--;
                    return true;
                }
            }
            return false;
        }

        private void addSeed(Seed seed, int count)
        {
            if (this.seedList == null) return;
            foreach (Seed sd in this.seedList)
            {
                if (sd.seedid == seed.seedid)
                {
                    sd.seednum = sd.seednum + count;
                    break;
                }
            }
        }

        private int seeding(int forUserNbr, Field fld, Seed seed)
        {
            string content = null;

            if ((this.hasPlantedMaxSharedFileds) && (forUserNbr != 0))
            {
                TraceLog.PrintLn("用户已经种植了最大数目的共享地！");
                return -1;
            }

            //买种子
            //如果用户当前列表里面没有这个种子，则重新购买该种子
            if (!this.hasSeed(seed))
            {
                TraceLog.Print("{0}.{1}: buyseed[{2}:{3}] ......", forUserNbr, fld.farmnum, seed.seedid, seed.name);
                content = KXWeb.Garden.Do_BuySeed(""+seed.seedid);
                if (content.IndexOf("succ") >= 0)
                {
                    TraceLog.PrintLn("succ");
                    this.addSeed(seed, 1);
                }
                else
                {
                    TraceLog.PrintLn("fail");
                    return 0;
                }
            }

            //播种
            if (forUserNbr == 0)
            {
                //自己的土地，用POST方式进行播种
                if (GardenAction(KXWeb.Garden.Action.FarmSeed, "0", fld.farmnum, "" + seed.seedid))
                {
                    fld.cropsstatus = 1;
                    this.addSeed(seed, -1);
                }
            }
            else
            {
                TraceLog.Print("{0}.{1}: farmseed(Get)[{2}:{3}] ......", forUserNbr, fld.farmnum, seed.seedid, seed.name);
                //对于朋友的土地，种植的方式与自己的土地稍有不同
                content = KXWeb.Garden.Do_FarmFriendSeed(""+forUserNbr, ""+seed.seedid, ""+fld.farmnum);
                if (content.IndexOf("succ") >= 0)
                {
                    TraceLog.PrintLn("succ");
                    this.addSeed(seed, -1);
                }
                else
                {
                    TraceLog.PrintLn("fail");
                    //<reason>你目前的级别，最多同时可种5块好友的地</reason>
                    string reason = TextParser.GetHtmlContent(content, "reason");
                    if (!String.IsNullOrEmpty(reason))
                    {
                        TraceLog.PrintLn(reason);
                        if (reason.IndexOf("最多同时可种") >= 0) this.hasPlantedMaxSharedFileds = true;
                    }
                }
            }

            return 0;
        }

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public class Fruit
        {
            public static Collection<Fruit> makeList(bool detailedInfo)
            {
                Collection<Fruit> fruitList = new Collection<Fruit>();

                //取得仓库内所有的果实列表
                string content = KXWeb.Garden.Get_MyGranary();
                if (content.IndexOf("succ") < 0) return fruitList;

                TextParser tp = new TextParser(content, "<item>", "</item>");
                string subCon = null;
                while ((subCon = tp.getNextStrBtw()) != null)
                {
                    Fruit ft = new Fruit();
                    ft.seedid = TextParser.GetInteger(TextParser.GetHtmlContent(subCon, "seedid"));
                    ft.fruitnum = TextParser.GetInteger(TextParser.GetHtmlContent(subCon, "num"));
                    fruitList.Add(ft);
                }

                //根据Fruit的数量多少对其进行排序
                int i = 0, j = 0;
                for (i = 0; i < fruitList.Count; i++)
                {
                    for (j = i + 1; j < fruitList.Count; j++)
                    {
                        if (fruitList[i].fruitnum < fruitList[j].fruitnum)
                        {
                            Fruit ft = fruitList[i];
                            fruitList[i] = fruitList[j];
                            fruitList[j] = ft;
                        }
                    }
                }

                //打印调试信息
                TraceLog.Print("仓库里有{0}种果实：", fruitList.Count);
                foreach (Fruit ft in fruitList)
                {
                    TraceLog.Print("[SD={0}]*{1}, ", ft.seedid, ft.fruitnum);
                }
                TraceLog.PrintLn("");

                if (detailedInfo)
                {
                    //取得单个果实的具体信息
                    foreach (Fruit ft in fruitList)
                    {
                        content = KXWeb.Garden.Get_MyFruitInfo("" + ft.seedid);
                        if (content.IndexOf("succ") < 0) continue;

                        ft.fruitprice = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fruitprice"));
                        ft.selfnum = TextParser.GetInteger(TextParser.GetHtmlContent(content, "selfnum"));
                        ft.bpresent = TextParser.GetInteger(TextParser.GetHtmlContent(content, "bpresent"));
                        ft.fruit_maxprice = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fruit_maxprice"));

                        TraceLog.PrintLn("果实SD-{0},持有{1}份，单价{2}元，供赠送={3}", ft.seedid, ft.fruitnum, ft.fruitprice, ft.bpresent);
                    }
                }
                return fruitList;
            }

            public int seedid;
            public int fruitnum;

            public int fruitprice;
            public int selfnum;
            public int bpresent;
            public int fruit_maxprice;

            public Fruit() { }

        }


        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public class Field
        {
            public int water = -1;
            public int farmnum = -1;
            public int vermin = 0;  // vermin == 1 有害虫  vermin == 0 无害虫
            public int cropsid = -1;
            public int fuid = -1;
            public int status = 0; //status == 0 不可操作   status == 1 正常   sattus == 2 干旱
            public int shared = -1;
            public int cropsstatus = -1; //cropsstatus == -1 没有庄稼  cropsstatus == 1  成长中   cropsstatus == 2  可以收获   cropsstatus == 3  收获过
            public int grow = -1;
            public int totalgrow = -1;
            public int fruitnum = -1;
            public int seedid = -1;
            public string crops = null;
            public string farm = null;
            public int grass = 0; // grass == 0 无杂草   grass == 1 需要除草
            public bool stealed = false;
            public DateTime harvestTime = System.DateTime.Now.ToLocalTime().AddDays(1);
            public static DateTime captureTime;

            public Field(string content)
            {
                this.water = TextParser.GetInteger(TextParser.GetHtmlContent(content, "water"));
                this.farmnum = TextParser.GetInteger(TextParser.GetHtmlContent(content, "farmnum"));
                this.vermin = TextParser.GetInteger(TextParser.GetHtmlContent(content, "vermin"));
                this.cropsid = TextParser.GetInteger(TextParser.GetHtmlContent(content, "cropsid"));
                this.fuid = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fuid"));
                this.status = TextParser.GetInteger(TextParser.GetHtmlContent(content, "status"));
                this.shared = TextParser.GetInteger(TextParser.GetHtmlContent(content, "shared"));
                this.cropsstatus = TextParser.GetInteger(TextParser.GetHtmlContent(content, "cropsstatus"));
                this.grow = TextParser.GetInteger(TextParser.GetHtmlContent(content, "grow"));
                this.totalgrow = TextParser.GetInteger(TextParser.GetHtmlContent(content, "totalgrow"));
                this.fruitnum = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fruitnum"));
                this.seedid = TextParser.GetInteger(TextParser.GetHtmlContent(content, "seedid"));
                this.grass = TextParser.GetInteger(TextParser.GetHtmlContent(content, "grass"));
                this.crops = TextParser.GetHtmlContent(content, "crops");
                this.farm = TextParser.GetHtmlContent(content, "farm");
                if ((this.crops != null) && (this.crops.IndexOf("已偷过") >= 0)) this.stealed = true;
                if ((this.crops != null) && (this.crops.IndexOf("距离收获：") >= 0))
                {
                    //string havestTime = Tool.GetMidString(this.crops, "距离收获：", "&lt;");
                    string havestTime = (new TextParser(this.crops)).getStrBtw("距离收获：", "&lt;");
                    int intMin = (new TextParser(havestTime)).getTotalMinutes();
                    this.harvestTime = Field.captureTime.AddMinutes(intMin);
                }
                if ((this.crops != null) && (this.crops.IndexOf("即将成熟") >= 0))
                {
                    //即将成熟的果子，过5分钟再来看
                    this.harvestTime = Field.captureTime.AddMinutes(5);
                }

                this.crops = this.removeHTML(this.crops);
                this.farm = this.removeHTML(this.farm);
            }

            private string removeHTML(string str)
            {
                string ret = null;
                if (str != null)
                {
                    ret = str.Replace("&lt;", "<");
                    ret = ret.Replace("&gt;", ">");
                    ret = ret.Replace("<br>", "; ");
                    ret = TextParser.NoHtml(ret);
                }
                return ret;
            }

            public static Collection<Field> makeList(string content)
            {
                Field.captureTime = System.DateTime.Now.ToLocalTime();
                Collection<Field> flst = new Collection<Field>();
                TextParser tp = new TextParser(content, "<item>", "</item>");
                string subContent = null;
                while ((subContent = tp.getNextStrBtw()) != null)
                {
                    Field fld = new Field(subContent);
                    flst.Add(fld);
                    TraceLog.PrintLn("  - [{0}]: SD={1}, WT={2}, VR={3}, GS={4}, SHR={5}, ST={6}, CST={7}",
                        fld.farmnum, fld.seedid, fld.water, fld.vermin, fld.grass, fld.shared, fld.status, fld.cropsstatus);
                    if (fld.crops != null)
                    {
                        TraceLog.PrintLn("        {0}; {1}", fld.crops, fld.farm);
                    }
                }
                return flst;
            }

        }

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public class Seed
        {
            public int seedid = -1;
            public string name = null;
            public int rank = -1;
            public int mhours = -1;
            public int price = -1;
            public int minprice = -1;
            public int maxprice = -1;
            public int minnum = -1;
            public int maxnum = -1;
            public int antisteal = -1;
            public int seednum = 0;

            public Seed()
            {

            }

            public Seed(int sID, string content)
            {
                this.seedid = sID;

                this.name = TextParser.GetHtmlContent(content, "name");
                this.rank = TextParser.GetInteger(TextParser.GetHtmlContent(content, "rank"));
                this.mhours = TextParser.GetInteger(TextParser.GetHtmlContent(content, "mhours"));
                this.price = TextParser.GetInteger(TextParser.GetHtmlContent(content, "price"));
                this.minprice = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fruit_minprice"));
                this.maxprice = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fruit_maxprice"));
                this.minnum = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fruit_minnum"));
                this.maxnum = TextParser.GetInteger(TextParser.GetHtmlContent(content, "fruit_maxnum"));
                this.antisteal = TextParser.GetInteger(TextParser.GetHtmlContent(content, "antistealdays"));
            }

            public static Collection<Seed> makeList()
            {
                Collection<Seed> seedList = new Collection<Seed>();

                //取得仓库内所有的果实列表
                string content = KXWeb.Garden.Get_MySeedList();
                if (content.IndexOf("succ") < 0) return seedList;

                TextParser tp = new TextParser(content, "<item>", "</item>");
                string subCon = null;
                while ((subCon = tp.getNextStrBtw()) != null)
                {
                    Seed sd = new Seed();
                    sd.seednum = TextParser.GetInteger(TextParser.GetHtmlContent(subCon, "num"));
                    sd.seedid = TextParser.GetInteger(TextParser.GetHtmlContent(subCon, "seedid"));
                    sd.name = TextParser.GetHtmlContent(subCon, "name");
                    seedList.Add(sd);
                }

                TraceLog.Print("种子列表里有：");
                foreach (Seed sd in seedList)
                {
                    TraceLog.Print("[SD={0}]*{1}, ", sd.seedid, sd.seednum);
                }
                TraceLog.PrintLn("");

                return seedList;
            }

            public static void printAllSeedInfo(string verifyCode)
            {
                int seedid = 1;
                while (true)
                {
                    string content = KXWeb.Garden.Get_Seedinfo("" + seedid);

                    if (null == content) break;
                    if (content.IndexOf("succ") < 0) break;

                    Seed sd = new Seed(seedid, content);
                    TraceLog.PrintLn("{0}   {1} {2} {3} {4} {5} {6} {7} {8} {9} ",
                        sd.seedid, sd.name, sd.rank, sd.minnum, sd.maxnum, sd.mhours, sd.antisteal,
                        sd.price, sd.minprice, sd.maxprice);
                    seedid++;
                }
            }
        }
    }

}
